package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;


@RequestMapping("/request")
@RestController
public class RequestController {
    @RequestMapping("/r1")
    public String r1(String username,String password){   //传入两个参数
        return "接收参数: username :"+username+",password: "+password;
    }

    @RequestMapping("/r2")
    public String r2(int num){   //传入一个参数
        return "接收参数: username :"+num;
    }

    @RequestMapping("/r3")
    public String r3(UserInfo userInfo){   //传入类
        return "接收参数: userInfo="+userInfo.toString();
    }

    //从前端接收参数q,赋值给keyword,必传参数,如果前段传入keyword会报错   @RequestParam("q") String keyword
    //@RequestParam(value = "q",required = false) String keyword  可以不必传  ,但是传入keyword也会找不到为null
    @RequestMapping("/r4")
    public String r3(@RequestParam(value = "q",required = false) String keyword){ //@RequestParam参数绑定,相当于把q赋值给了keyword
        return "接收参数: keyword="+keyword;
    }


    @RequestMapping("/r5")
    public String r5(int[]arr){   //传入数组
        return "接收参数: 数组"+ Arrays.toString(arr);
    }

    @RequestMapping("/r6")
    public String r5(@RequestParam List<Integer> list){   //传递集合
        return "接收参数: 数组"+list;
    }


}



/*
@RequestMapping("/request")
@RestController
public class RequestController {
    @RequestMapping("/r1")
    public String r1(String keyword){   //传入一个参数
        return "接收参数"+keyword;
    }
}*/
